package com.example.demo.nuoqi.controller;

import com.example.demo.nuoqi.pojo.Reply;
import com.example.demo.nuoqi.service.ReplyService;
import com.example.demo.nuoqi.utils.Result;
import com.example.demo.nuoqi.utils.StatusCode;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "ReplyController")
@RestController
@RequestMapping("/reply")
@CrossOrigin
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    /***
     * Reply分页条件搜索实现
     * @param reply
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "Reply条件分页查询",notes = "分页条件查询Reply方法详情",tags = {"ReplyController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "Reply对象",value = "传入JSON数据",required = false) Reply reply, @PathVariable int page, @PathVariable int size){
        //调用ReplyService实现分页条件查询Reply
        PageInfo<Reply> pageInfo = replyService.findPage(reply, page, size);
        return new Result(true, StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * Reply分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "Reply分页查询",notes = "分页查询Reply方法详情",tags = {"ReplyController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable int page, @PathVariable int size){
        //调用ReplyService实现分页查询Reply
        PageInfo<Reply> pageInfo = replyService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     *
     * @param reply
     * @return
     */
    @ApiOperation(value = "Reply条件查询",notes = "条件查询Reply方法详情",tags = {"ReplyController"})
    @PostMapping(value = "/search" )
    public Result<List<Reply>> findList(@RequestBody(required = false) @ApiParam(name = "Reply对象",value = "传入JSON数据",required = false) Reply reply){
        //调用ReplyService实现条件查询Reply
        List<Reply> list = replyService.findList(reply);
        return new Result<List<Reply>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Reply根据ID删除",notes = "根据ID删除Reply方法详情",tags = {"ReplyController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用ReplyService实现根据主键删除
        replyService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改Reply数据
     * @param reply
     * @param id
     * @return
     */
    @ApiOperation(value = "Reply根据ID修改",notes = "根据ID修改Reply方法详情",tags = {"ReplyController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "Reply对象",value = "传入JSON数据",required = false) Reply reply, @PathVariable Integer id){
        //设置主键值
        reply.setId(id);
        //调用ReplyService实现修改Reply
        replyService.update(reply);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增Reply数据
     * @param reply
     * @return
     */
    @ApiOperation(value = "Reply添加",notes = "添加Reply方法详情",tags = {"ReplyController"})
    @PostMapping
    public Result add(@RequestBody @ApiParam(name = "Reply对象",value = "传入JSON数据",required = true) Reply reply){
        //调用ReplyService实现添加Reply
        replyService.add(reply);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询Reply数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Reply根据ID查询",notes = "根据ID查询Reply方法详情",tags = {"ReplyController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<Reply> findById(@PathVariable Integer id){
        //调用ReplyService实现根据主键查询Reply
        Reply reply = replyService.findById(id);
        return new Result<Reply>(true,StatusCode.OK,"查询成功",reply);
    }

    /***
     * 查询Reply全部数据
     * @return
     */
    @ApiOperation(value = "查询所有Reply",notes = "查询所Reply有方法详情",tags = {"ReplyController"})
    @GetMapping
    public Result<List<Reply>> findAll(){
        //调用ReplyService实现查询所有Reply
        List<Reply> list = replyService.findAll();
        return new Result<List<Reply>>(true, StatusCode.OK,"查询成功",list) ;
    }




}
